<template>
    <button @click="minusnum">-1</button>
    <input type="text" v-model="mycount">
    <button @click="addnum">+1</button>
</template>

<script setup>
import { computed, ref, watch } from 'vue';
const prop = defineProps(['count'])
const emit = defineEmits(['setcount','onMinus','onPlus'])
// const num = ref()

function addnum(){
    emit('onPlus');

}
function minusnum(){
    emit('onMinus');

}

// watch(()=>num.value,()=>{
//     emit('setcount',num.value)
// })
// // 侦听器
// watch(()=>prop.count,()=>{
//     num.value=prop.count;
// })

const mycount = computed({
    get(){
        return prop.count;
    },
    set(newValue){
        emit('setcount',newValue)
    }
})

</script>


<style scoped>

</style>